/*本模块功能:成绩管理(详情)
        编写者:朱光曜
        编写时间:2017.11.03*/
$(function() {
    var string1 = '<tr>' +
        '<th class="col-lg-4">平时成绩</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">平时成绩换算值</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">考试成绩</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">考试成绩换算值</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">总得分</th>' +
        '</tr>';

    function totalScore(data) {//总成绩
        var str="";
        /*if(data.detailMap.sumSource==0){
        	str="暂无统计";
        }else{*/
        str=data.detailMap.sumSource;
        //}
        return '<tr data-num="0">' +
            '<td class="col-lg-4">'+data.detailMap.preforSource+'分</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.detailMap.finPromaceSource+'</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.detailMap.examSource+'分</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.detailMap.finExamSource+'</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+str+'分</td>' +
            '</tr>';

    }
    var string2 = '<tr>' +
        '<th class="col-lg-4">序号</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">章节名称</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">类型</th>' +
        '<th class="style"></th>' +
        '<th class="col-lg-4">得分</th>' +
        '</tr>';
    var loading1 = new Loading();//监控全局ajax添加loading
    loading1.init();
    $(document).ajaxSend(function(){
        loading1.show();

    });
    $(document).ajaxStop(function(){
        loading1.hide();

    });
    function academicGPA(data) {//平时成绩

        return '<tr data-num="0">' +
            '<td class="col-lg-4">'+(parseInt(key)+1) +'</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.courseList[key].chapterName+'</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.courseList[key].typeName+'</td>' +
            '<td class="style"></td>' +
            '<td class="col-lg-4">'+data.courseList[key].taskSoruce+'分</td>' +
            '</tr>';

    }
    var nowData = 1;
    var index = {

        init: function() {
            this.bind();
        },
        bind: function() {
            var self = this;
            this.data_content = {}; //搜索集
            this.tab_content = {}; //列表集
            this.parameter = {
                "classId":parseInt(result.paramData.classId),
                "courseId":parseInt(result.paramData.courseId),
                "stuorteaId":result.paramData.stuorteaId
            };

            this.postData(this.parameter, nowData);

        },
        tab_add: function() { //列表追加
            var self = this;
            var data = self.tab_content;
            var table = string1;
            var table1 = string2;

            //data.detailMap={};

            $(".mainContent .message_tit span").html(data.userName);
            //data.detailMap="";
            if(data.detailMap!="") {


                table += totalScore(data);



                $(".mainContent .totalScore").html(table);
            } else {
                var trImg = '<td class="col-lg-4">0</td><td class="style"></td><td class="col-lg-4">0</td><td class="style"></td><td class="col-lg-4">0</td><td class="style"></td><td class="col-lg-4">0</td><td class="style"></td><td class="col-lg-4">0</td>';

                $(".mainContent .totalScore").html(string1+ trImg);
            }

            var j = 0;
            for(key in data.courseList) {//追加平时成绩
                j++;
            }
            //j=0;
            if(j > 0) {

                for(key in data.courseList) {

                    table1 += academicGPA(data);

                }

                $(".mainContent .academicGPA").html(table1);
            } else {
                var trImg = "<tr><td colspan='4'><img style='margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></td/tr>";
                $(".mainContent .academicGPA").html(string2+trImg);
            }
            //设置列表宽度(最大为9)
            var numMax = 0;
            $(".totalScore tr th").each(function() {
                var str = $(this).attr("class");
                if(str !== "style") {
                    var num = str.lastIndexOf("col-lg-") + 7;
                    var num1 = parseFloat(str.substring(num, num + 1));

                    numMax += num1;
                }
            });

            $(".totalScore tr th").each(function() {
                var str = $(this).attr("class");
                if(str !== "style") {
                    var num = str.lastIndexOf("col-lg-") + 7;
                    var num1 = parseFloat(str.substring(num, num + 1));

                    $(this).css("width", num1 / numMax * 100 + "%");
                }
            });
            //设置列表宽度(最大为9)
            var numMax1 = 0;
            $(".academicGPA tr th").each(function() {
                var str = $(this).attr("class");
                if(str !== "style") {
                    var num = str.lastIndexOf("col-lg-") + 7;
                    var num1 = parseFloat(str.substring(num, num + 1));
                    numMax1 += num1;
                }
            });

            $(".academicGPA tr th").each(function() {
                var str = $(this).attr("class");
                if(str !== "style") {
                    var num = str.lastIndexOf("col-lg-") + 7;
                    var num1 = parseFloat(str.substring(num, num + 1));

                    $(this).css("width", num1 / numMax1 * 100 + "%");
                }
            });
        },
        postData: function(par_data, nowData,hunt) { //获得搜索及列表数据
            var self = this;
            var parameter = par_data;

            $.ajax({
                type: "post",
                url: "getStuSourceDetail",
                async: true,
                data:{
                    "jsonStr":	JSON.stringify(parameter)
                },
                success: function(data, status, xhr) {
                    var new_data = JSON.parse(data);

                    self.tab_content = new_data;

                    self.tab_add();


                },
                error: function(data, status, xhr) {
                    var json = JSON.stringify({
                        "pageName": "error"
                    });
                    window.location.href = "skipPage?jsonStr=" + json;

                }
            });
        }

    };

    index.init();

});